package com.cy.pj.sys.web.controller;

import com.cy.pj.common.pojo.JsonResult;
import com.cy.pj.sys.pojo.SysMenu;
import com.cy.pj.sys.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController()
@RequestMapping("/menu/")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;


    //@RequestBody接收的参数时Json格式,如果不是则不能修改或者插入,415异常可能是提交的格式不是　json格式
    @PutMapping
    public JsonResult doUpdateMenu(@RequestBody SysMenu menu){
        int a = sysMenuService.updateMenu(menu);
        if(a>=1){
            return new JsonResult("Update Ok");
        }else{
            return new JsonResult("记录已经不存在");
        }

    }

    @PostMapping
    public JsonResult doSaveMenu(@RequestBody SysMenu menu){
        sysMenuService.saveMenu(menu);
        return new JsonResult("Save OK");
    }
    @GetMapping("treeNodes")
    public JsonResult doFindMenuTreeNodes(){
        return new JsonResult(sysMenuService.findMenuTreeNodes());
    }
    @GetMapping
    public JsonResult doFindMenus(){
        return new JsonResult(sysMenuService.findMenus());
    }
}
